package ws.very.common.web.views.entity

case class Paging[+T](found: I, start: I, page: I, items: T, itemsCount: I) {
  lazy val maxPage = found / itemsCount + (if (found % itemsCount > 0) 1 else 0)
  def parRange(l: I) = {
    val half = (l - 1) / 2
    val maybeStart = page - half
    //    val maybeEnd=maybeStart +l-1
    def end(maybeEnd: I) =
      if (maybeEnd < maxPage) maybeEnd else maxPage
    if (maybeStart > 0)
      maybeStart to (end(maybeStart + l - 1))
    else 1 to (end(l))
  }
}